<cfcomponent displayname="browser" output="false" namespace="org.rickosborne.util" hint="Browser Detector and Handler">
	<cfset this.AppName="">
	<cfset this.AppVersion="">
	<cfset this.OSName="">
	<cfset this.OSVersion="">
	<cfset this.ua=CGI.HTTP_USER_AGENT>
	<cfset this.AppREs=ListToArray("Opera|Safari|Konqueror!MSIE|Firefox!Mozilla","!")>
	<cfset this.OSREs=ListToArray("Windows NT|Mac OS X!Macintosh|Windows","!")>
	<cffunction name="init" output="false" returntype="browser" description="Initialize our object" displayname="init">
		<cfset var RE=1>
		<cfset var ver="">
		<cfloop condition="RE LTE ArrayLen(this.AppREs)">
			<cfset ver=REFindNoCase("(#this.AppREs[RE]#)[ /]([0-9][.]?[0-9]*)",this.ua,1,True)>
			<cfif ArrayLen(ver.pos) EQ 3>
				<cfset this.AppName=Mid(this.ua,ver.pos[2],ver.len[2])>
				<cfset this.AppVersion=Val(Mid(this.ua,ver.pos[3],ver.len[3]))>
				<cfset RE=ArrayLen(this.AppREs)>
			</cfif>
			<cfset RE=RE+1>
		</cfloop>
		<cfset RE=1>
		<cfloop condition="RE LTE ArrayLen(this.OSREs)">
			<cfset ver=REFindNoCase("(#this.OSREs[RE]#)[ /]?([0-9][.]?[0-9]*)?",this.ua,1,True)>
			<cfif ArrayLen(ver.pos) GT 1>
				<cfset this.OSName=Mid(this.ua,ver.pos[2],ver.len[2])>
				<cfif (ArrayLen(ver.pos) GT 2) AND (ver.pos[3] GT 0) AND (ver.len[3] GT 0)>
					<cfset this.OSVersion=Val(Mid(this.ua,ver.pos[3],ver.len[3]))>
				</cfif>
				<cfset RE=ArrayLen(this.OSREs)>
			</cfif>
			<cfset RE=RE+1>
		</cfloop>
		<cfreturn this />
	</cffunction>
	<cffunction name="isMac" returntype="boolean" output="false" description="Is this browser running on Macintosh?" displayname="isMac">
		<cfreturn (FindNoCase("Mac",this.OSName,1) GT 0) />
	</cffunction>
	<cffunction name="isWin" returntype="boolean" output="false" description="Is this browser running on Windows?" displayname="isWin">
		<cfreturn (FindNoCase("Win",this.OSName,1) GT 0) />
	</cffunction>
	<cffunction name="cssClasses" returntype="string" output="false" description="A set of short CSS-friendly classes that contain the browser and version" displayname="cssClasses">
		<cfset var ret=LCase(this.AppName)>
		<cfif IsNumeric(this.AppVersion)>
			<cfset ret=ListAppend(ret,LCase(this.AppName) & Int(this.AppVersion))>
			<cfset ret=ListAppend(ret,LCase(this.AppName) & Int(this.AppVersion*10))>
		</cfif>
		<cfif this.isMac()><cfset ret=ListAppend(ret,"mac")></cfif>
		<cfif this.isWin()><cfset ret=ListAppend(ret,"win")></cfif>
		<cfreturn ListChangeDelims(ret," ")>
	</cffunction>
</cfcomponent>
